<?php
require_once ($_SERVER['DOCUMENT_ROOT'].'/global_oracle.php');
require_once ($_SERVER['DOCUMENT_ROOT'].'/global2.php');
//导入新教师
$oracle_array = array();
$mysql_array = array();
//汇文中的学号
$sql = "select a.code08 from libsys.reader a where a.redr_type_code = '01'";
$query = oci_parse($connect,$sql);
oci_execute($query,OCI_DEFAULT);
while ($a = oci_fetch_assoc($query)) {
  $oracle_array[] = $a['CODE08'];
}
//勤工俭学系统中的学号
$sql = "select XueHao from user where LeiBie = 1";
$query = $mysqli->query($sql);
while ($a = $query->fetch_assoc()) {
  $mysql_array[] = $a['XueHao'];
}
//比较差异
$diffrent = array_diff($oracle_array,$mysql_array);
$XueHaoString = "'";
$index = 1;
foreach ( $diffrent  as $value  ) {
  $XueHaoString .= $value."','";
  $index++;
  if ($index > 990) {
      break;
  }
}
echo $XueHaoString = substr($XueHaoString,0,-2);
exit;
//导入差异
$sql = "select a.name,a.id_card,a.code08,a.redr_type_code,a.redr_flag,'25d55ad283aa400af464c76d713c07ad' mima from libsys.reader a where a.code08 in ({$XueHaoString})";
$query = oci_parse($connect,$sql);
oci_execute($query,OCI_DEFAULT);
while ($a = oci_fetch_assoc($query)) {
  echo $a['NAME'].',';
  $sql = "Insert into user (XingMing,XueHao,IdNumber,LeiBie,Status,MiMa)
          values (
          '{$a['NAME']}',
          '{$a['CODE08']}',
          '{$a['ID_CARD']}',
          {$a['REDR_TYPE_CODE']},
          {$a['REDR_FLAG']},
          '{$a['MIMA']}'
          )
          ";
  $mysqli->query($sql);
}
//导入新学生
$oracle_array = array();
$mysql_array = array();
//汇文中的学号
$sql = "select a.code08 from libsys.reader a where a.redr_type_code = '02'";
$query = oci_parse($connect,$sql);
oci_execute($query,OCI_DEFAULT);
while ($a = oci_fetch_assoc($query)) {
  $oracle_array[] = $a['CODE08'];
}
//勤工俭学系统中的学号
$sql = "select XueHao from user where LeiBie = 2";
$query = $mysqli->query($sql);
while ($a = $query->fetch_assoc()) {
  $mysql_array[] = $a['XueHao'];
}
//比较差异
$diffrent = array_diff($oracle_array,$mysql_array);
$XueHaoString = "'";
foreach ( $diffrent  as $value  ) {
  $XueHaoString .= $value."','";
}
$XueHaoString = substr($XueHaoString,0,-2);
//导入差异
// $sql = "select a.name,a.id_card,a.code08,a.redr_type_code,a.redr_flag,'25d55ad283aa400af464c76d713c07ad' mima from libsys.reader a where a.code08 in ({$XueHaoString}) and a.code08 > '202108001'";
$sql = "select a.name,a.id_card,a.code08,a.redr_type_code,a.redr_flag,'25d55ad283aa400af464c76d713c07ad' mima from libsys.reader a where a.code08 in ({$XueHaoString}) and a.code08 > '202108001'";
$query = oci_parse($connect,$sql);
oci_execute($query,OCI_DEFAULT);
while ($a = oci_fetch_assoc($query)) {
  echo $a['NAME'].',';
  $sql = "Insert into user (XingMing,XueHao,IdNumber,LeiBie,Status,MiMa)
          values (
          '{$a['NAME']}',
          '{$a['CODE08']}',
          '{$a['ID_CARD']}',
          {$a['REDR_TYPE_CODE']},
          {$a['REDR_FLAG']},
          '{$a['MIMA']}'
          )
          ";
  $mysqli->query($sql);
}
$sql = "ALTER TABLE `user` auto_increment = 1";
$mysqli->query($sql);

exit;
?>

